package zezutom.designpatterns.cor;

/**
 *
 * @author tomasz
 */
public abstract class GenericHandler implements RequestHandler {

    public static final String REQUEST_APPROVED = "%d $$ Loan approved for %s - Approved by %s";
    
    private String name;

    private RequestHandler successor;    
    
    protected abstract int getLimit();
    
    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean handleRequest(LoanRequest request) {
        boolean approved = false;
        
        if (request.getAmount() < getLimit()) {
            System.out.println(String.format(REQUEST_APPROVED, request.getAmount(), request.getCustomer(), getName()));
            approved = true;
        }
        return approved;
    }    
}
